<template>

  <div class="container">

    <div class="header">
      <img class="logo" src="../../assets/img/logo.png"/>
    </div>

    <div id="navigation">

      <div class="title"><span class="span">欢迎进入！</span>openLooKeng集群管理平台</div>

      <div class="card">
        <el-input style="width:350px;" prefix-icon="el-icon-user" placeholder="账号" v-model="loginUser" size="medium"></el-input>
        <el-input style="width:350px;margin:20px 0 40px;" prefix-icon="el-icon-lock" placeholder="密码" v-model="loginPW" type="password" size="medium" @keyup.enter.native="logined"></el-input>
        <el-button type="primary" @click="logined" size="medium" style="width:350px;height:45px;font-size:24px;">登录</el-button>
        <el-button type="primary" @click="goToRegister" size="medium" style="width:350px;height:45px;font-size:24px;margin:20px 0;">注册</el-button>
      </div>

    </div>

  </div>
</template>
<script>
  import {loginByAccount} from '@/api/index.js'

  export default {
    data ()
    {
      return {
        loginUser: '',
        loginPW: '',
      }
    },

    methods:
    {
      //the username and password when login
      logined ()
      {
        localStorage.setItem('number', this.loginUser)
        if (this.loginUser != '' && this.loginPW != '')
        {
          let obj = {account: this.loginUser, passWord: this.loginPW}
          loginByAccount(obj).then((response) =>
          {
            if (response.data.code == 0)
            {
              localStorage.setItem('userInfo', JSON.stringify(response.data.data))
              this.$message({
                showClose: true,
                message: '登陆成功',
                type: 'success'
              })
              this.$router.push('/bashbord')
              this.$store.commit("getUserInfo")
            }
          })
        }
        else
        {
          this.$message({
            showClose: true,
            message: '用户名和密码不能为空',
            type: 'warning'
          })
        }
      },
      goToRegister()
      {
        this.$router.push({path:'/register'});
      }
    },
  }
</script>
<style scoped>

  .container
  {
    width:1920px;
    height:1080px;
  }

  #navigation {
    width:1920px;
    height:1020px;
    display:flex;
    flex-direction:column;
    align-items:center;
    background: url("../../assets/img/bg.png") center center no-repeat;
    background-size: 100% 100%;
  }

  .flexd {
    position: absolute;
    width: 31%;
    height: 53%;
    background: #ffffff;
    border-radius: 5px;
    top: 20%;
    left: 50%;
  }

  .card {
    width:630px;
    height:413px;
    box-shadow: 0px 2px 20px 0px rgba(0, 0, 0, 0.1);
    background: #FFFFFF;
    border-radius: 8px;
    border: 1px solid rgba(229, 229, 229, 0.97);
    display:flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .span {
    font-size: 20px;
  }

  .title {
    height: 48px;
    font-size: 30px;
    font-family: PingFangSC-Medium, PingFang SC;
    line-height: 50px;
    text-align: center;
    margin: 117px 0 110px ;
  }
</style>
